home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / The Hacks! / SloppyWindows / SloppyWindows.cp < prev    next >
Encoding:
Text File  |  1998-06-21  |  1.9 KB  |  90 lines  |  [TEXT/CWIE]

  1.  
  2. #include <A4Stuff.h>
  3. #include <SetUpA4.h>
  4. #include <Traps.h>
  5. #include <Windows.h>
  6. #include <Resources.h>
  7. #include <Sound.h>
  8.  
  9.  
  10. typedef pascal OSErr (*PostEventType)(short eventNum,long eventMsg);
  11. PostEventType    oldPostEvent;
  12.  
  13. typedef pascal void (*ProcessMgrDispatchType)(short selector);
  14. ProcessMgrDispatchType oldProcessMgrDispatch;
  15.  
  16. static pascal OSErr myPostEvent2(short eventNum,long eventMsg)
  17. {
  18.     short    resultCode = noErr;
  19.     Boolean    doIt = true;
  20.     
  21.     EnterCallback();
  22.     if ( eventNum == mouseDown )
  23.         {
  24.         WindowPeek    frontWindow    = (WindowPeek)FrontWindow();
  25.         if ( frontWindow && !PtInRgn( LMGetRawMouseLocation(), frontWindow->strucRgn ) )
  26.             {
  27.             RgnHandle    rgn = NewRgn();
  28.             CopyRgn( frontWindow->strucRgn, rgn );
  29.             InsetRgn( rgn, -10, 0 );
  30.             if ( PtInRgn( LMGetRawMouseLocation(), frontWindow->strucRgn ) )
  31.                 {
  32.                 SysBeep(5);
  33.                 doIt = false;
  34.                 }
  35.             DisposeRgn( rgn );
  36.             }
  37.         }
  38.  
  39.     if (doIt)
  40.         resultCode    = (oldPostEvent)(eventNum, eventMsg);
  41.     ExitCallback();
  42.     return    resultCode;
  43. }
  44.  
  45. asm static pascal OSErr myPostEvent(short eventNum,long eventMsg)
  46. {
  47.     link a6,#0
  48.     move.l a0,-(a7)
  49.     move.l d0,-(a7)
  50.     jsr myPostEvent2
  51.     move.l (a7)+,d0
  52.     unlk a6
  53.     rts
  54. }
  55.  
  56.  
  57. static pascal void myWatchForProcessMgr(short selector)
  58. {
  59.     ProcessMgrDispatchType localTrapAddress;
  60.     
  61.     EnterCodeResource();
  62.  
  63.     if (selector == 1)
  64.     {
  65.         // install findwindow patch here
  66.         oldPostEvent = (PostEventType)GetOSTrapAddress( _PostEvent );
  67.         SetOSTrapAddress( (UniversalProcPtr)myPostEvent, _PostEvent );
  68.     }
  69.  
  70.     localTrapAddress = oldProcessMgrDispatch;
  71.     ExitCodeResource();
  72.     
  73.     (*oldProcessMgrDispatch)(selector);
  74. }
  75.  
  76. void main( void )
  77. {
  78.     EnterCodeResource();
  79.     PrepareCallback();
  80.     
  81.     Handle    myHandle    = Get1Resource( 'INIT', 300 );
  82.     DetachResource( myHandle );
  83.     HLock( myHandle );
  84.     
  85.     oldProcessMgrDispatch = (ProcessMgrDispatchType)GetToolTrapAddress( 0xABCF );
  86.     SetToolTrapAddress( (UniversalProcPtr)myWatchForProcessMgr, 0xABCF );
  87.     
  88.     ExitCodeResource();
  89. }
  90.